package com.geccocrawler.gecco.utils;


import org.apache.commons.dbutils.QueryRunner;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectDb {  
    private static String driveClassName = "com.mysql.jdbc.Driver";  
    private static String url = "jdbc:mysql://localhost:3306/gecco?useUnicode=true&characterEncoding=utf8";   
      
    private static String user = "root";  
    private static String password = "root";

    static Connection conn = null;
      
    public static Connection Connect(){
          
        //load driver  
        try {  
            Class.forName(driveClassName);  
        } catch (ClassNotFoundException  e) {  
            System.out.println("load driver failed!");  
            e.printStackTrace();  
        }  
          
        //connect db  
        try {
            if(conn == null) {
                conn = DriverManager.getConnection(url, user, password);
            }
        } catch (SQLException e) {  
            System.out.println("connect failed!");  
            e.printStackTrace();  
        }
        return conn;  
    }  
    
    public static void main(String[] args){
        Connection connection = Connect();
        QueryRunner queryRunner = new QueryRunner();
        String sql = "insert into agent values(null, ?, ?)";
        try {
            queryRunner.update(connection, sql, "1","1");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
} 